//
//  AngelLeftMenuViewController.m
//  GoodWayClient
//
//  Created by HuiDong on 15/12/14.
//  Copyright © 2015年 HuiDong. All rights reserved.
//

#import "AngelLeftMenuViewController.h"
#import "GoodsManagerViewController.h"
#import "AppDelegate.h"
#import "AccountTableViewController.h"
#import "ExperienceVoucherManagerTableViewController.h"
#import "CompanyTableViewController.h"
#import "IntegralAmountTableViewController.h"
#import "LeftMenuTopTableViewCell.h"
#import "CommendHistoryTableViewController.h"
#import "WantCommendViewController.h"

@interface AngelLeftMenuViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)NSDictionary *dic;

@end

@implementation AngelLeftMenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageview.image = [UIImage imageNamed:@"bg.png"];
    [self.view addSubview:imageview];
    
    UITableView *tableview = [[UITableView alloc] init];
    self.tableview = tableview;
    tableview.frame = self.view.bounds;
    tableview.dataSource = self;
    tableview.delegate  = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//懒加载
- (NSDictionary *)dic
{
    if (!_dic) {
        _dic = @{@"head":@"logo",@"name":@"蓝天使者"};
    }
    return _dic;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *Identifier = @"Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"账户信息";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    } else if (indexPath.row == 1) {
        cell.textLabel.text = @"体验券管理";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"我的链盟商";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    } else if (indexPath.row == 3) {
        cell.textLabel.text = @"积分/金额";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    } else if (indexPath.row == 4) {
        cell.textLabel.text = @"商品管理";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    } else if (indexPath.row == 5) {
        cell.textLabel.text = @"我要推荐";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    }else if (indexPath.row == 6) {
        cell.textLabel.text = @"推荐历史";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    }else if (indexPath.row == 7) {
        cell.textLabel.text = @"退出登录";
        cell.imageView.image = [UIImage imageNamed:@"logo"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    if (indexPath.row == 0) {
        //账户信息
        AccountTableViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"AccountTableViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
        
    }else if (indexPath.row == 1)
    {
        //体验券管理
        ExperienceVoucherManagerTableViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"ExperienceVoucherManagerTableViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
    }else if (indexPath.row == 2)
    {
        //我的联盟商
        CompanyTableViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"CompanyTableViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
        
    }else if (indexPath.row == 3)
    {
        //积分与金额
        IntegralAmountTableViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"IntegralAmountTableViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
    }else if (indexPath.row == 4)
    {
        //商品管理
        GoodsManagerViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"GoodsManagerViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
    }else if (indexPath.row == 5)
    {
        //我要推荐
        WantCommendViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"WantCommendViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
    }else if (indexPath.row == 6)
    {
        //推荐历史
        CommendHistoryTableViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"CommendHistoryTableViewController"];
        [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉
        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
    }else
    {
        //退出登录
        [self.delegate clear];
        [tempAppDelegate.LeftSlideVC back];
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [[UIScreen mainScreen] bounds].size.height*0.08;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return [[UIScreen mainScreen] bounds].size.height*0.3;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    LeftMenuTopTableViewCell *cell = [LeftMenuTopTableViewCell LeftMenuTopWithTableView:tableView];
    cell.backgroundColor = [UIColor clearColor];
    cell.dic = self.dic;
    return cell;
}

@end
